package checkers_seperate_classes;

/**
 * A CheckersMove object represents a move in the game of Checkers.
 * It holds the row and column of the piece that is to be moved
 * and the row and column of the square to which it is to be moved.
 * (This class makes no guarantee that the move is legal.)   
 */
public class CheckersMove {
	private final int fromRow, fromCol;  // Position of piece to be moved.
	private final int toRow, toCol;      // Square it is to move to.
	public CheckersMove(int r1, int c1, int r2, int c2) {
		// Constructor.  Just set the values of the instance variables.
		fromRow = r1;
		fromCol = c1;
		toRow = r2;
		toCol = c2;
	}
	public CheckersMove(CheckersMove move) {
		this(move.fromRow,move.fromCol,move.toRow, move.toCol);
	}
	public boolean isJump() {
		// Test whether this move is a jump.  It is assumed that
		// the move is legal.  In a jump, the piece moves two
		// rows.  (In a regular move, it only moves one row.)
		return (fromRow - toRow == 2 || fromRow - toRow == -2);
	}
	public String toString() {
		String rtn = "";
		if (isJump()) {
			rtn = "jump";
		} else {
			rtn = "move";
		}
		rtn = rtn+" from "+(fromRow+1)+", "+(fromCol+1)+" to "+(toRow+1)+", "+(toCol+1);
		return rtn;
	}
	public CheckersMove clone() {
		return new CheckersMove(this);
	}
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + fromCol;
		result = prime * result + fromRow;
		result = prime * result + toCol;
		result = prime * result + toRow;
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof CheckersMove)) {
			return false;
		}
		CheckersMove other = (CheckersMove) obj;
		if (fromCol != other.fromCol) {
			return false;
		}
		if (fromRow != other.fromRow) {
			return false;
		}
		if (toCol != other.toCol) {
			return false;
		}
		if (toRow != other.toRow) {
			return false;
		}
		return true;
	}
	public int getFromRow() {
		return fromRow;
	}
	public int getFromCol() {
		return fromCol;
	}
	public int getToRow() {
		return toRow;
	}
	public int getToCol() {
		return toCol;
	}
}  // end class CheckersMove.

